package com.nail.api.customMake.dao;

import com.nail.api.customMake.bean.Message;
import com.nail.dao.IBaseDao;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
@Mapper
public interface IMessageDao extends IBaseDao<Message> {

	
	@Update("update message set is_read = 1 where id = #{messageId}")
	public void setIsRead(@Param("messageId") String messageId);

	@Select("select * from message where  accepter = #{userId} ORDER BY is_read ASC,create_time DESC limit #{start},#{end} ")
	public List<Message> getMessageByUserId(@Param("userId")Long userId, @Param("start")Integer start, @Param("end")Integer end);

	@Select("select * from message where  accepter = #{userId} and is_read = 0 ORDER BY is_read ASC,create_time DESC limit #{start},#{end} ")
	public List<Message> getUnReadMessageByUserId(@Param("userId")Long userId, @Param("start")Integer start, @Param("end")Integer end);
	
	@Select("select count(1) as num from message where  accepter = #{userId}")
	public Integer getMessageByUserIdCount(@Param("userId")Long userId);

	@Select("select count(1) as num from message")
	public Integer getMessageCountAll();

	@Select("select * from message ORDER BY is_read ASC,create_time DESC limit #{start},#{end} ")
	public List<Message> getMessage(@Param("start")Integer start,@Param("end")Integer end);
	
}
